﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace KD.Sms.UI_Sys
{
    public partial class frmChangePwd : Form
    {
        public frmChangePwd()
        {
            InitializeComponent();
        }

        private void tools_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e)
        {
            if (e.Tool.Key == "Save")
            {
                if (txtNow.Text.Trim() != CacheUser.User_PassWord)
                {
                    UI.MsgBox.Show(UI.MsgType.Error, "当前登录密码输入错误!");
                    txtNow.Focus();
                }
                else
                {
                    if (txtOne.Text.Trim() != txtTwo.Text.Trim())
                    {
                        UI.MsgBox.Show(UI.MsgType.Error, "两次输入密码不一致!");
                        txtOne.Text = string.Empty;
                        txtTwo.Text = string.Empty;
                        txtOne.Focus();
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(txtOne.Text.Trim()))
                        {
                            UI.MsgBox.Show(UI.MsgType.Error, "修改密码不能为空!");
                            txtOne.Focus();
                        }
                        else
                        {
                            if (DAL.SqlLite.Main.Instance.DoChangeUserPwd(CacheUser.User_Id, DesEncrypt.Encrypt(txtOne.Text.Trim())))
                            {
                                DAL.SqlLite.Main.Instance.LogWrite(SysLogType.Login, "成功修改登录密码");

                                UI.MsgBox.Show(UI.MsgType.Information, "密码修改成功，下次登录生效!");
                                this.Close();
                            }
                        }
                    }
                }
            }
            else
            {
                this.Close();
            }
        }

        private void frmChangePwd_Load(object sender, EventArgs e)
        {

        }
    }
}
